@extends("admin.base")
@section("page")
    <div class="container-fluid p-4">
        <h3>电影国籍管理页面</h3>
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <a href="countryaddpage">
                            <button class="btn btn-primary waves-effect"> 添加</button>
                        </a>
                        <div class="table-responsive mt-3">
                            <table class="table mb-0">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th>中文名称</th>
                                    <th>维吾尔文名称</th>
                                    <th>排序</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($countries as $ct)
                                    <tr>
                                        <th scope="row">{{$ct->id}}</th>
                                        <td>{{$ct->name_ch}}</td>
                                        <td>{{$ct->name_uy}}</td>
                                        <td>{{$ct->order}}</td>
                                        <td>
                                            <a href="countryaddpage?id={{$ct->id}}">
                                                <button class="btn btn-success"> 编辑</button>
                                            </a>
                                            <button onclick="del({{$ct->id}})" class="btn btn-danger"> 删除</button>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
@endsection

@section("scripts")
    <style>
        .swal-footer {
             text-align: center;
            padding-top: 13px;
            margin-top: 13px;
            padding: 13px 16px;
            border-radius: inherit;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }
    </style>
    <script>
        function del(id) {
            swal({
                title: "确认操作",
                text: "如果数据被删除，无法恢复，确认删除吗",
                icon: "warning",
                buttons: ["取消", "删除"],
            }).then((willDelete) => {
                if (willDelete) {
                    $.ajax({
                        url:"http://dil.aynakedu.com/countrydelete",    //请求的url地址
                        dataType:"json",   //返回格式为json
                        async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                        headers:{'X-CSRF-TOKEN':'{{csrf_token()}}' },
                        data: {"id":id},    //参数值
                        type:"get",   //请求方式
                        success:function(req){
                            if(req.err == 0){
                                swal({
                                    title: "操作成功",
                                    text: req.title,
                                    icon: "success",
                                    button: "知道了",
                                });
                                setTimeout(function (){
                                    location.reload();
                                },2000)
                            }
                        },
                        error:function(err){
                            //请求出错处理
                        }
                    });
                }else{

                }
            });
        }
    </script>
@endsection
